
const NetUtils = {
    GET(...args) {
        return new Promise((resolve, reject) => jQuery.getJSON(...args, data => (data.success ? resolve : reject)(data.data)).error(reject));
    },
    POST(...args) {
        return new Promise((resolve, reject) => jQuery.post(...args, data => (data.success ? resolve : reject)(data.data)).error(reject));
    },
    UPLOAD(url, formData) {
        return new Promise((resolve, reject) => {
            jQuery.ajax({
                url: url,
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function(data) {
                    if (data && data.success) {
                        resolve(data.data);
                    } else {
                        reject(data ? data.data : undefined);
                    }
                },
                error: function(err) {
                    reject(err);
                }
            });
        });
    },
    FETCH: fetch
};

export default NetUtils;